/*
 *  Theroy0039_ClassifiedChordsTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 11/07/17.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#include "Theory0039_ClassifiedChordsTester.h"
#include "../Theroy0039_ClassifiedChords.h"
#include "../../../sc/Tester/CustomAssert.h"

namespace theory0039
{
	void ClassifiedChordsTester::TestAll()
	{
		Test_AddChord();

		Test_AddChords();

		Test_GetClassCount();
		
		Test_GetIdOfIndex();

		Test_GetIndexOfId();

		Test_GetChords();

	}

	void ClassifiedChordsTester::Test_AddChord()
	{
		Chord c( sc::Note::A, sc::Note::AFlat );
		ClassifiedChords cc;
		std::string id = "test";
		cc.AddId( "test" );
		cc.AddId( "test_number1" );
		cc.AddChord( id, c );

		const std::vector< Chord >& chordsGotten = cc.GetChords( id );
		AssertEqual( chordsGotten.size(), 1 );
		AssertEqual( chordsGotten[ 0 ].GetNoteCount(), 2 );
		AssertTrue( chordsGotten[ 0 ].IsIncludeNote( sc::Note::A ) );
		AssertTrue( chordsGotten[ 0 ].IsIncludeNote( sc::Note::AFlat ) );

		c = Chord( sc::Note::B, sc::Note::BFlat, sc::Note::EFlat );
		cc.AddChord( id, c );
		const std::vector< Chord >& chordsGotten2 = cc.GetChords( id );
		AssertEqual( chordsGotten2.size(), 2 );
		AssertEqual( chordsGotten2[ 0 ].GetNoteCount(), 2 );
		AssertTrue( chordsGotten2[ 0 ].IsIncludeNote( sc::Note::A ) );
		AssertTrue( chordsGotten2[ 0 ].IsIncludeNote( sc::Note::AFlat ) );

		AssertEqual( chordsGotten2[ 1 ].GetNoteCount(), 3 );
		AssertTrue( chordsGotten2[ 1 ].IsIncludeNote( sc::Note::B ) );
		AssertTrue( chordsGotten2[ 1 ].IsIncludeNote( sc::Note::BFlat ) );
		AssertTrue( chordsGotten2[ 1 ].IsIncludeNote( sc::Note::EFlat ) );

		cc.AddChord( id = id + std::string( "_number1" ), c );
		const std::vector< Chord >& chordsGotten3 = cc.GetChords( id );
		AssertEqual( chordsGotten3.size(), 1 );
		AssertEqual( chordsGotten3[ 0 ].GetNoteCount(), 3 );
		AssertTrue( chordsGotten3[ 0 ].IsIncludeNote( sc::Note::B ) );
		AssertTrue( chordsGotten3[ 0 ].IsIncludeNote( sc::Note::BFlat ) );
		AssertTrue( chordsGotten3[ 0 ].IsIncludeNote( sc::Note::EFlat ) );

	}

	void ClassifiedChordsTester::Test_AddChords()
	{
		Chord c0( sc::Note::A, sc::Note::AFlat );
		Chord c1( sc::Note::A, sc::Note::AFlat, sc::Note::E );
		Chord c2( sc::Note::A, sc::Note::AFlat, sc::Note::E, sc::Note::EFlat );

		std::vector< Chord > cs;
		cs.push_back( c0 );
		cs.push_back( c1 );
		cs.push_back( c2 );

		ClassifiedChords cc;
		cc.AddChords( "test", cs );
		const std::vector< Chord >& csOut = cc.GetChords( "test" ); 
		AssertEqual( csOut.size(), 3 );
		AssertEqual( csOut[ 0 ].GetNoteCount(), 2 );
		AssertEqual( csOut[ 1 ].GetNoteCount(), 3 );
		AssertEqual( csOut[ 2 ].GetNoteCount(), 4 );
	}

	void ClassifiedChordsTester::Test_GetClassCount()
	{
		Chord c( sc::Note::A, sc::Note::AFlat );
		ClassifiedChords cc;

		AssertEqual( cc.GetClassCount(), 0 );

		cc.AddId( "test" );
		cc.AddId( "test2" );

		std::string id_ = "test";
		cc.AddChord( id_, c );
		AssertEqual( cc.GetClassCount(), 2 );

		id_ = "test2";
		cc.AddChord( id_, c );
		AssertEqual( cc.GetClassCount(), 2 );

		id_ = "test";
		cc.AddChord( id_, c );
		AssertEqual( cc.GetClassCount(), 2 );
	}

	void ClassifiedChordsTester::Test_GetIdOfIndex()
	{
		Chord c( sc::Note::A, sc::Note::AFlat );
		ClassifiedChords cc;
		std::string id = "test";
		
		AssertEqual( -1, cc.GetIndexOfId( id ) );
	}

	void ClassifiedChordsTester::Test_GetIndexOfId()
	{
		Chord c( sc::Note::A, sc::Note::AFlat );
		ClassifiedChords cc;
		std::string id = "test";
		cc.AddId( "test" );
		cc.AddId( "test2" );

		AssertEqual( 0, cc.GetIndexOfId( id ) );

		cc.AddChord( id, c );
		AssertEqual( cc.GetIndexOfId( id ), 0 );

		std::string id2 = "test2";
		cc.AddChord( id2, c );

		AssertEqual( cc.GetIndexOfId( id ), 0 );
		AssertEqual( cc.GetIndexOfId( id2 ), 1 );

	}

	void ClassifiedChordsTester::Test_GetChords()
	{
		Chord c0( sc::Note::A, sc::Note::AFlat );
		Chord c1( sc::Note::A, sc::Note::AFlat, sc::Note::E );
		Chord c2( sc::Note::A, sc::Note::AFlat, sc::Note::E, sc::Note::EFlat );

		std::vector< Chord > cs;
		cs.push_back( c0 );
		cs.push_back( c1 );
		cs.push_back( c2 );

		ClassifiedChords cc;
		cc.AddId( "id" );
		cc.AddChords( "id", cs );
		const std::vector< Chord >& csOut = cc.GetChords( "id" ); 
		AssertEqual( csOut.size(), 3 );
		AssertEqual( csOut[ 0 ].GetNoteCount(), 2 );
		AssertEqual( csOut[ 1 ].GetNoteCount(), 3 );
		AssertEqual( csOut[ 2 ].GetNoteCount(), 4 );
	}

}